package com.vonchenchen.simple_downloader.downloader;

import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.ExecutorService;

/**
 * 下载控制块
 * Created by lidechen on 9/15/16.
 */
public class DownLoadInfo {

    public static ExecutorService POOL_TASK;

    public static final int STATUS_RESUME = 1;
    public static final int STATUS_PAUSE = 2;

    public static LinkedList<DownLoadInfo> mBusyDownLoadTaskList;

    public boolean isStart = false;

    /** 文件总长度 */
    public long totleLength;
    /** 当前进度 */
    public long currLength;

    /** 待下载的url */
    public String urlStr;
    /** 存储路径 */
    public String localPath;

    public int status;

    public Map<Integer, ThreadInfo> mThreadInfoMap;

    public DownLoadTask mDownLoadTask = null;

    /**
     * 开启载
     */
    public synchronized void execDownLoadTask(){
        if(mDownLoadTask != null){
            mDownLoadTask.setDownLoadInfo(DownLoadInfo.this);
            isStart = true;
            POOL_TASK.execute(mDownLoadTask);
            //mDownLoadTask.execDownLoadTask();
        }
    }

    public synchronized void addToDownLoadTask(){
        mBusyDownLoadTaskList.add(DownLoadInfo.this);
    }

    public synchronized void removeFromDownLoadTask(){
        if(isStart == true && mBusyDownLoadTaskList != null){
            mBusyDownLoadTaskList.remove(mDownLoadTask);
            isStart = false;
        }
    }
}
